﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;

namespace Terraria.ModLoader
{
	// Token: 0x02000211 RID: 529
	public static class NPCHeadLoader
	{
		// Token: 0x06001729 RID: 5929 RVA: 0x0041791C File Offset: 0x00415B1C
		internal static int ReserveHeadSlot()
		{
			int result = NPCHeadLoader.nextHead;
			NPCHeadLoader.nextHead++;
			return result;
		}

		// Token: 0x0600172A RID: 5930 RVA: 0x0041793C File Offset: 0x00415B3C
		internal static int ReserveBossHeadSlot(string texture)
		{
			if (NPCHeadLoader.bossHeads.ContainsKey(texture))
			{
				return NPCHeadLoader.bossHeads[texture];
			}
			int result = NPCHeadLoader.nextBossHead;
			NPCHeadLoader.nextBossHead++;
			return result;
		}

		// Token: 0x0600172B RID: 5931 RVA: 0x00011AD8 File Offset: 0x0000FCD8
		public static int GetHeadSlot(string texture)
		{
			if (NPCHeadLoader.heads.ContainsKey(texture))
			{
				return NPCHeadLoader.heads[texture];
			}
			return -1;
		}

		// Token: 0x0600172C RID: 5932 RVA: 0x00011AF4 File Offset: 0x0000FCF4
		public static int GetBossHeadSlot(string texture)
		{
			if (NPCHeadLoader.bossHeads.ContainsKey(texture))
			{
				return NPCHeadLoader.bossHeads[texture];
			}
			return -1;
		}

		// Token: 0x0600172D RID: 5933 RVA: 0x00417978 File Offset: 0x00415B78
		internal static void ResizeAndFillArrays()
		{
			Array.Resize<Texture2D>(ref Main.npcHeadTexture, NPCHeadLoader.nextHead);
			Array.Resize<Texture2D>(ref Main.npcHeadBossTexture, NPCHeadLoader.nextBossHead);
			foreach (string text in NPCHeadLoader.heads.Keys)
			{
				Main.npcHeadTexture[NPCHeadLoader.heads[text]] = ModLoader.GetTexture(text);
			}
			foreach (string text2 in NPCHeadLoader.bossHeads.Keys)
			{
				Main.npcHeadBossTexture[NPCHeadLoader.bossHeads[text2]] = ModLoader.GetTexture(text2);
			}
			foreach (int num in NPCHeadLoader.npcToBossHead.Keys)
			{
				NPCID.Sets.BossHeadTextures[num] = NPCHeadLoader.npcToBossHead[num];
			}
		}

		// Token: 0x0600172E RID: 5934 RVA: 0x00417A9C File Offset: 0x00415C9C
		internal static void Unload()
		{
			NPCHeadLoader.nextHead = NPCHeadLoader.vanillaHeadCount;
			NPCHeadLoader.nextBossHead = NPCHeadLoader.vanillaBossHeadCount;
			NPCHeadLoader.heads.Clear();
			NPCHeadLoader.bossHeads.Clear();
			NPCHeadLoader.npcToHead.Clear();
			NPCHeadLoader.headToNPC.Clear();
			NPCHeadLoader.npcToBossHead.Clear();
		}

		// Token: 0x0600172F RID: 5935 RVA: 0x00011B10 File Offset: 0x0000FD10
		internal static int GetNPCHeadSlot(int type)
		{
			if (NPCHeadLoader.npcToHead.ContainsKey(type))
			{
				return NPCHeadLoader.npcToHead[type];
			}
			return -1;
		}

		// Token: 0x06001730 RID: 5936 RVA: 0x00011B2C File Offset: 0x0000FD2C
		internal static int GetNPCFromHeadSlot(int slot)
		{
			if (NPCHeadLoader.headToNPC.ContainsKey(slot))
			{
				return NPCHeadLoader.headToNPC[slot];
			}
			return -1;
		}

		// Token: 0x040015EA RID: 5610
		public static readonly int vanillaHeadCount = Main.npcHeadTexture.Length;

		// Token: 0x040015EB RID: 5611
		public static readonly int vanillaBossHeadCount = Main.npcHeadBossTexture.Length;

		// Token: 0x040015EC RID: 5612
		private static int nextHead = NPCHeadLoader.vanillaHeadCount;

		// Token: 0x040015ED RID: 5613
		private static int nextBossHead = NPCHeadLoader.vanillaBossHeadCount;

		// Token: 0x040015EE RID: 5614
		internal static IDictionary<string, int> heads = new Dictionary<string, int>();

		// Token: 0x040015EF RID: 5615
		internal static IDictionary<string, int> bossHeads = new Dictionary<string, int>();

		// Token: 0x040015F0 RID: 5616
		internal static IDictionary<int, int> npcToHead = new Dictionary<int, int>();

		// Token: 0x040015F1 RID: 5617
		internal static IDictionary<int, int> headToNPC = new Dictionary<int, int>();

		// Token: 0x040015F2 RID: 5618
		internal static IDictionary<int, int> npcToBossHead = new Dictionary<int, int>();
	}
}
